<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/10/12
 * Time: 10:50
 */

namespace app\portal\controller;
use cmf\controller\HomeBaseController;
use app\portal\model\ActivityModel;
use app\portal\model\UserOrganizeModel;
use think\Db;

class ControllController extends HomeBaseController
{
    //交管员社区首页
    public function index()
    {
        $model = new ActivityModel();
        $data=$model->where('org_id',3)->limit(5)->select();
        //明星交管员
        $patrol=Db::name('traffic_controll')->order('patrol desc')->limit(7)->select();
        $man_car=Db::name('traffic_controll')->order('man_car desc')->limit(7)->select();
        $road=Db::name('traffic_controll')->order('road desc')->limit(7)->select();
        $talent=Db::name('traffic_controll')->where('status',1)->select();
        $this->assign('data',$data);
        $this->assign('patrol',$patrol);
        $this->assign('man_car',$man_car);
        $this->assign('road',$road);
        $this->assign('talent',$talent);
        return $this->fetch(':controll');
    }
    //交管员活动列表
    public function activity_list(){
            $model=new ActivityModel();
            $act_show=$model->with('organize')->with('user')->where('end_date','<',time()-60*60*24)->where('org_id',3)->paginate(10); //活动展示
            $act_adv=$model->with('organize')->with('user')->where('start_date','>',time())->where('org_id',3)->paginate(10);  //活动预告
            $this->assign('act_show',$act_show);
            $this->assign('act_adv',$act_adv);
            $this->assign('page_show',$act_show->render());
            $this->assign('page_adv',$act_adv->render());
            return $this->fetch(':controll_activity');
    }
    public function apply(){
        $user=session('user');
        $org_id = input('org_id');
        $model=new UserOrganizeModel();
        if($user){
            $find=$model->where(['user_id'=>$user['id'],'org_id'=>$org_id])->find();
            if($find){
                if($find['status']==1){
                    $this->error('您已提交申请并通过审核，请勿重复提交!', url('/'));
                }
                $this->error('您已提交申请!，请勿重复提交!', url('/'));
            }
        }
        $this->assign('org_id',$org_id);
        return $this->fetch(':apply');
    }
}